#!/usr/bin/env python3
"""
临时脚本：从customfilelistwidget.cpp中移除响应式相关代码
"""

import re

def main():
    with open('customfilelistwidget.cpp', 'r', encoding='utf-8') as f:
        content = f.read()

    # 移除响应式相关的代码块
    patterns_to_remove = [
        r'if \(m_responsiveModeEnabled\) \{\s*clearAllResponsiveItems\(\);\s*\} else \{\s*clearAllItems\(\);\s*\}',
        r'if \(m_responsiveModeEnabled\) \{\s*createResponsiveItemsFromParentData\(\);\s*\} else',
        r'if \(m_responsiveModeEnabled\) \{[^}]*\}',
        r'm_responsiveModeEnabled',
        r'clearAllResponsiveItems\(\)',
        r'createResponsiveItemsFromParentData\(\)',
        r'switchToResponsiveMode\(\)',
        r'switchToTraditionalMode\(\)',
        r'enableResponsiveMode\([^)]*\)',
        r'isResponsiveModeEnabled\(\)',
        r'setResponsiveEngine\([^)]*\)',
        r'getResponsiveEngine\(\)',
        r'updateResponsiveLayout\(\)',
        r'onResponsiveItemClicked\([^)]*\)',
        r'onResponsiveItemRightClicked\([^)]*\)',
        r'onResponsiveItemDragStarted\([^)]*\)',
        r'onResponsiveItemDoubleClicked\([^)]*\)',
        r'onDisplayModeChanged\([^)]*\)',
        r'connectResponsiveItemSignals\([^)]*\)',
        r'getResponsiveItemIndex\([^)]*\)',
        r'clearAllResponsiveItems\(\)',
        r'm_responsiveEngine',
        r'm_responsiveItems',
        r'ResponsiveFileItem\*',
        r'ResponsiveFileListEngine\*',
    ]

    # 简单替换，移除响应式相关的行
    lines = content.split('\n')
    cleaned_lines = []
    skip_line = False

    for line in lines:
        # 检查是否包含响应式相关内容
        if any(pattern in line for pattern in [
            'm_responsiveModeEnabled',
            'clearAllResponsiveItems',
            'createResponsiveItemsFromParentData',
            'switchToResponsiveMode',
            'switchToTraditionalMode',
            'enableResponsiveMode',
            'isResponsiveModeEnabled',
            'setResponsiveEngine',
            'getResponsiveEngine',
            'updateResponsiveLayout',
            'onResponsiveItem',
            'onDisplayModeChanged',
            'connectResponsiveItemSignals',
            'getResponsiveItemIndex',
            'm_responsiveEngine',
            'm_responsiveItems',
            'ResponsiveFileItem*',
            'ResponsiveFileListEngine*'
        ]):
            # 跳过这些行
            continue

        cleaned_lines.append(line)

    # 移除空行
    result = '\n'.join(cleaned_lines)
    result = re.sub(r'\n\s*\n\s*\n', '\n\n', result)

    with open('customfilelistwidget_cleaned.cpp', 'w', encoding='utf-8') as f:
        f.write(result)

    print("清理完成，输出到 customfilelistwidget_cleaned.cpp")

if __name__ == '__main__':
    main()